/***********************************************************
 
 File name: AAUserDefaults.h
 Author:    xuwei
 Description:
 对 NSUserDefaults 的简单封装, 使用类方法更简便易用.
 
 History:
 2018/02/27: Created
 
 ************************************************************/

#import "AAUserDefaults.h"

#define UDSynchronize [USER_DEFAULTS synchronize]

@implementation AAUserDefaults

#pragma mark - 基本数据类型

+ (void)setBool:(BOOL)value forKey:(NSString *)defaultName {
    [USER_DEFAULTS setBool:value forKey:defaultName];
    UDSynchronize;
}

+ (BOOL)boolForKey:(NSString *)defaultName {
    return [USER_DEFAULTS boolForKey:defaultName];
}

+ (void)setInteger:(NSInteger)value forKey:(NSString *)defaultName {
    [USER_DEFAULTS setInteger:value forKey:defaultName];
    UDSynchronize;
}

+ (NSInteger)integerForKey:(NSString *)defaultName {
    return [USER_DEFAULTS integerForKey:defaultName];
}

+ (void)setFloat:(float)value forKey:(NSString *)defaultName {
    [USER_DEFAULTS setFloat:value forKey:defaultName];
    UDSynchronize;
}

+ (float)floatForKey:(NSString *)defaultName {
    return [USER_DEFAULTS floatForKey:defaultName];
}

+ (void)setDouble:(double)value forKey:(NSString *)defaultName {
    [USER_DEFAULTS setDouble:value forKey:defaultName];
    UDSynchronize;
}

+ (double)doubleForKey:(NSString *)defaultName {
    return [USER_DEFAULTS doubleForKey:defaultName];
}

#pragma mark - 对象类型

+ (void)setString:(NSString *)value forKey:(NSString *)defaultName {
    [self setObject:value forKey:defaultName];
}

+ (NSString *)stringForKey:(NSString *)defaultName {
    return [USER_DEFAULTS stringForKey:defaultName];
}

+ (void)setArray:(NSArray *)value forKey:(NSString *)defaultName {
    [self setObject:value forKey:defaultName];
}

+ (NSArray *)arrayForKey:(NSString *)defaultName {
    return [USER_DEFAULTS arrayForKey:defaultName];
}

+ (void)setDictionay:(NSDictionary *)value forKey:(NSString *)defaultName {
    [self setObject:value forKey:defaultName];
}

+ (NSDictionary<NSString *,id> *)dictionaryForKey:(NSString *)defaultName {
    return [USER_DEFAULTS dictionaryForKey:defaultName];
}

+ (void)setData:(NSData *)value forKey:(NSString *)defaultName {
    [self setObject:value forKey:defaultName];
}

+ (NSData *)dataForKey:(NSString *)defaultName {
    return [USER_DEFAULTS dataForKey:defaultName];
}

+ (void)setObject:(id)value forKey:(NSString *)defaultName {
    [USER_DEFAULTS setObject:value forKey:defaultName];
    UDSynchronize;
}

+ (id)objectForKey:(NSString *)defaultName {
    return [USER_DEFAULTS objectForKey:defaultName];
}

+ (void)removeObjectForKey:(NSString *)defaultName {
    [USER_DEFAULTS removeObjectForKey:defaultName];
}
@end
